﻿/*
This software is copyright 2009 Matthew Wilson matthew@wilson.org
and available under the Artistic License 2 ("AL2") as documented at
http://jsmeta.googlecode.com
*/

var callTree, treeRoot, msgCount = 0;
var callTraceNodeAdd, callTraceNodeStatus, callTraceNewInput;

var treeTrace = false;
  treeTrace = true;

if (typeof(treeTrace)!='undefined' && treeTrace) {
  $(function() {
    $("#callTrace").dynatree({
      minExpandLevel: 2
    , clickFolderMode: 3
    });
    callTree = $("#callTrace").dynatree("getTree");
    treeRoot = $("#callTrace").dynatree("getRoot");
  });
  
  callTraceNodeAdd = function(nodeId, parentNodeId, nodeTitle) {
    (parentNodeId!==null ? callTree.getNodeByKey('act_' + parentNodeId) : treeRoot).append({
      key: 'act_'+nodeId,
      title: msgCount++ + ' actId: ' + nodeId + ' rule: ' + nodeTitle,
      isFolder: true,
      expand: true
    });
  }
  callTraceNodeStatus = function(nodeId, nodeStatus) {
    callTree.getNodeByKey('act_' + nodeId).append({
      title:  msgCount++ + ' actId: ' + nodeId + ' ' + nodeStatus,
      isFolder: false
    });
  }
  callTraceNewInput = function(inputStr) {
    treeRoot.append({
      title: '<strong>----------------------------------------------------------------------------------New Input String: ' + inputStr.toProgramString() + '</strong>',
      isFolder: false
    });
  }
} else {
  callTraceNodeAdd = callTraceNodeStatus = callTraceNewInput = function() {
    Print(Array.prototype.join.call(arguments, ' '));
  }
}